// 检查是否处于离线模式
export function isOfflineMode() {
  // 检查浏览器是否支持 navigator.onLine
  if (typeof navigator !== "undefined" && "onLine" in navigator) {
    return !navigator.onLine
  }
  return false // 默认假设在线
}

// 获取本地存储中的离线模式设置
export function getOfflineModePreference() {
  if (typeof localStorage !== "undefined") {
    return localStorage.getItem("offlineMode") === "true"
  }
  return false
}

// 设置离线模式偏好
export function setOfflineModePreference(value: boolean) {
  if (typeof localStorage !== "undefined") {
    localStorage.setItem("offlineMode", value ? "true" : "false")
  }
}

// 数据类型定义
export type Poll = {
  id: string
  title: string
  description: string | null
  active: boolean
  created_at: string
}

export type PollOption = {
  id: string
  poll_id: string
  text: string
  votes: number
}

export type Comment = {
  id: string
  poll_id: string
  text: string
  created_at: string
}
